export default {
	name: "forgot-pwd",
	data() {
		const phone = (rule, value, callback) => {
			if (!this.validation.Phone(value)) {
				callback(new Error());
			}
			callback();
		};
		return {
			sysUser: {
				userName: "",
				phone: "",
				securityCode: ""
			},
			rules: {
				userName: [
					{required: true, message: "请输入账号", trigger: "blur"},
					{min: 1, max: 16, message: "长度在 1 到 16 个字符", trigger: "blur"}
				],
				phone: [
					{required: true, message: "请输入手机号码", trigger: "blur"},
					{validator: phone, message: "手机号码格式无效，为11位数字", trigger: "blur"}
				],
				securityCode: [
					{required: true, message: "请输入验证码", trigger: "blur"},
					{min: 6, max: 6, message: "长度为6个字符", trigger: "blur"}
				]
			}
		};
	},
	methods: {
		//密码重置
		resetPwd() {
			this.$refs.resetForm.validate((valid) => {
				if (valid) {
					this.fetch.resetPwd(this.sysUser,
						(res) => {
							this.message.success("密码重置成功!");
							//修改密码成功后跳转到登录界面
							this.$router.push("/");
						},
						(error) => {
							console.log(error);
						});
				} else {
					this.message.error("表单数据提交错误!");
					return false;
				}
			});
		}
	}
};
